//Healing (Code to heal other players (increase Ring count or HP))
/*addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid then -- check if the player object exists
    
        if player.mo.skin ~= "annie_belnades" then -- is the player NOT playing as Annie?
            return -- stop running hook for this player
        end
		
		if player.custom1down == nil then
			player.custom1down = 0
		end
		
		if player.cmd.buttons & BT_CUSTOM1 > 0 then
			player.custom1down = $1 + 1
		else
			player.custom1down = 0
		end
		
		if player.custom1down > 1
		and player.var.energy >= 5*FRACUNIT/2 then
			if (player.panim == PA_IDLE or player.mo.state == S_PLAY_ANNIE_HEALING) and not (leveltime%4) --Dirfex's carrying code is being used as a foundation for nearby player detection.
			
			local found = false
			searchBlockmap("objects", function(pmo, mo)
				if not mo.player or not mo.player.valid return end
				if mo.player.panim ~= PA_ABILITY
				and mo.z > pmo.z + p.moheight and mo.z < p.moz + p.moheight + 55*FRACUNIT
					found = true
					player.mo.state = S_PLAY_ANNIE_HEALING
					p.dfx.playercarry = (R_PointToDist2(pmo.x, pmo.y, mo.x, mo.y) < 32*FRACUNIT and (mo.z - pmo.z)/FRACUNIT < 80)
				end
			end, p.mo, p.mo.x, p.mo.x + 25*FRACUNIT, p.mo.y, p.mo.y + 25*FRACUNIT)
		end
			if player.mo.state == S_PLAY_ANNIE_HEALING and not found
				player.mo.state = S_PLAY_STND
			end
		end
	end
end)

//Accelerated Healing (Code to double the speed of healing)
addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid then
	
		if player.mo.skin ~= "annie_belnades" then
			return
		end
		
		if player.custom1down == nil then
			player.custom1down = 0
		end
		
		if player.cmd.buttons & BT_CUSTOM1 > 0 then
			player.custom1down = $1 + 1
		else
			player.custom1down = 0
		end
		
		if player.custom1down > 1 -- if custom1 is currently being pressed
		and player.custom3down > 1 -- and custom3 is also currently being pressed
		and player.custom1down > player.custom3down -- and custom1 was pressed *before* custom3
		and player.var.energy >= 5*FRACUNIT then -- and the player has energy
//			apply PF_RAPIDHEALING
		end
	end
end)

//Emergency Carry (Code to carry other players so they don't have to manually stay within 20-fracunit healing & revival range)
addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid then
	
		if player.mo.skin ~= "annie_belnades" then
			return
		end
		
		if player.custom2down == nil then
			player.custom2down = 0
		end
		
		if player.cmd.buttons & BT_CUSTOM2 > 0 then
			player.custom2down = $1 + 1
		else
			player.custom2down = 0
		end
		
		if player.custom2down > 1 then
			//Dirfex's carrying code is being used as a placeholder and foundation. The intention is:
				--Annie can freely move around, including jumping and double-jumping (but not spin-dashing) while carrying a player
				--Annie can pick up another player regardless of whether she or the other player are in the air or on the ground
				--Annie receives the SF_NOJUMPSPIN and SF_NOJUMPDAMAGE flags while carrying a player (cannot damage enemies by jumping into them), but can damage enemies with Vixen Vortex
				--The other player can make Annie drop them at any time by pressing Move Left, Move Right, Move Forward, Move Back, Jump, or Spin
				--Annie's movement parameters (normalspeed, thrustfactor, accelstart, acceleration, jumpfactor) are reduced if she is carrying a character above a certain large size or weight class, including robots
				--Annie cannot pick up characters above a certain larger size or weight class at all
			if (player.panim == PA_IDLE or player.mo.state == S_PLAY_ANNIE_EMERGENCYCARRY) and not (leveltime%4)
			
			local found = false
			searchBlockmap("objects", function(pmo, mo)
				if not mo.player or not mo.player.valid return end
				if mo.player.panim ~= PA_ABILITY
				and mo.z > pmo.z + pmo.height and mo.z < pmo.z + pmo.height + 55*FRACUNIT
					found = true
					player.mo.state = S_PLAY_ANNIE_EMERGENCYCARRY
					p.dfx.playercarry = (R_PointToDist2(pmo.x, pmo.y, mo.x, mo.y) < 32*FRACUNIT and (mo.z - pmo.z)/FRACUNIT < 80)
				end
			end, p.mo, p.mo.x, p.mo.x + 25*FRACUNIT, p.mo.y, p.mo.y + 25*FRACUNIT)
		
			if player.mo.state == S_PLAY_ANNIE_EMERGENCYCARRY and not found
				player.mo.state = S_PLAY_STND
			end

		end

		//If we entered our carrying position that means we can now carry players, so let's spawn something on top of us to hold 'em
		if player.mo.state == S_PLAY_ANNIE_EMERGENCYCARRY

			player.mo.sprite2 = p.dfx.playercarry and SPR2_DSEG or SPR2_STND
			//We'll spawn an invisible gargoyle on top of Annie to be used as a carrying platform
			if not p.dfx.carrygoyle or (p.dfx.carrygoyle and not p.dfx.carrygoyle.valid)
				if p.dfx.carrygoyle and not p.dfx.carrygoyle.valid then p.dfx.carrygoyle = nil end
				p.dfx.carrygoyle = P_SpawnMobjFromMobj(p.mo, 0, 0, 0, MT_GARGOYLE)
				p.dfx.carrygoyle.flags = $ | MF_NOGRAVITY | MF_NOCLIPHEIGHT & ~MF_PUSHABLE & ~MF_SLIDEME
				p.dfx.carrygoyle.flags2 = $ | MF2_DONTDRAW
				p.dfx.carrygoyle.radius = 8*FRACUNIT
			end

			//Put the carrygoyle where it should be
			P_TeleportMove(p.dfx.carrygoyle, p.mo.x, p.mo.y, p.mo.z + p.mo.height/2)
			
			if p.cmd.forwardmove or p.cmd.sidemove or (p.cmd.buttons & BT_JUMP) or (p.cmd.buttons & BT_SPIN)
				if p.dfx.carrygoyle and p.dfx.carrygoyle.valid then P_RemoveMobj(p.dfx.carrygoyle) end
				p.dfx.carrygoyle = nil
				player.mo.state = S_PLAY_WALK
			end
		else
			if p.dfx.carrygoyle
				if p.dfx.carrygoyle.valid then P_RemoveMobj(p.dfx.carrygoyle) end
				p.dfx.carrygoyle = nil
				end
			end
		end
	end
end)

//Revive (Code to resurrect other players)
addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid then
	
		if player.mo.skin ~= "annie_belnades" then
			return
		end
		
		if player.custom3down == nil then
			player.custom3down = 0
		end
		
		if player.cmd.buttons & BT_CUSTOM3 > 0 then
			player.custom3down = $1 + 1
		else
			player.custom3down = 0
		end
		
		if player.custom3down > 1 -- if custom3 is currently being pressed
		and player.var.energy >= 50*FRACUNIT/6 then -- and enough energy is available to at least make progress on revival
			
		end
	end
end)

//Accelerated Revival (Code to resurrect other players faster, but not be able to move)
addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid then
	
		if player.mo.skin ~= "annie_belnades" then
			return
		end
		
		if player.custom3down == nil then
			player.custom3down = 0
		end
		
		if player.cmd.buttons & BT_CUSTOM3 > 0 then
			player.custom3down = $1 + 1
		else
			player.custom3down = 0
		end
		
		if player.custom3down > 1 -- if custom3 is currently being pressed
		and player.custom1down > 1 -- and if custom1 is also currently being pressed
		and player.custom3down > custom1down -- and if custom3 was pressed *before* custom1
		and player.var.energy >= 50*FRACUNIT/4 then -- and enough energy is available to at least make progress on revival
			
		end
	end
end)*/